def key = session.user.id + '-todayTranscations'
if(!memcache.contains(key)) {
	def date = new Date()
	date.hours = 0
	date.minutes = 0
	def tentities = datastore.execute {
		from TranscationE
		sort desc by createdTime
		where userId == session.user.id and createdTime > date
	}

	def transcationTags = [:]
	def tagTotal = [:]
	def todayTotal = 0.0
	tentities.each { transcation ->
		def ttentities = datastore.execute {
			from TranscationTagE
			sort asc by name
			where transcationId == transcation.key.id and userId == session.user.id
		}
		def tags = new StringBuilder()
		ttentities.each { tt ->
			tags += "<a class=\"table-1-link\" href=\"transcationViewForTag.groovy?transcationTag=$tt.name\">#$tt.name</a> "
			if(tagTotal[tt.name] == null) {
				tagTotal[tt.name] = 0
			}
			tagTotal[tt.name] += transcation.amount
		}
		todayTotal += transcation.amount
		transcationTags[transcation.key.id] = tags
	}
	
	key = session.user.id + '-todayTranscations'
	memcache[key] = tentities
	//System.out.println(tentities)
	key = session.user.id + '-todayTagTotal'
	memcache[key] = tagTotal
	//System.out.println(tagTotal)
	key = session.user.id + '-todayTotal'
	memcache[key] = String.format("%.2f", todayTotal)
	//System.out.println(todayTotal)
	key = session.user.id + '-todayTranscationTags'
	memcache[key] = transcationTags
	//System.out.println(transcationTags)
}
request.transcationTags = memcache[session.user.id + '-todayTranscationTags']
request.tagTotal = memcache[session.user.id + '-todayTagTotal']
request.total = memcache[session.user.id + '-todayTotal']
request.transcations = memcache[session.user.id + '-todayTranscations']

//System.out.println(request.transcationTags)
//System.out.println(request.tagTotal)
//System.out.println(request.total)
//System.out.println(request.transcations)

forward 'transcationViewForToday.gsp'